package com.qf.commerce.controller;

import com.github.pagehelper.PageInfo;
import com.qf.commerce.common.dto.DistributorOrderDto;
import com.qf.commerce.common.dto.DistributorOrderSelectDto;
import com.qf.commerce.common.vo.DistributorOrderVo;
import com.qf.commerce.resp.ResponseResult;
import com.qf.commerce.service.DistributorOrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/dealer/order")
public class DistributorOrderController {

    @Resource
    private DistributorOrderService distributorOrderService;

    /**
     * 分页展示所有经销商订单
     *
     * @param page page
     * @param size size
     * @return com.qf.commerce.resp.ResponseResult<com.github.pagehelper.PageInfo < com.qf.commerce.common.vo.DistributorOrderVo>>
     * @author 358
     * @since JDK 1.8
     */
    @GetMapping("/list")
    public ResponseResult<PageInfo<DistributorOrderVo>> list(@RequestParam(name = "page",defaultValue = "1") Integer page,@RequestParam(name = "size",defaultValue = "6") Integer size) {
        try {
            return ResponseResult.success(distributorOrderService.list(page, size));
        } catch (Exception e) {
            return ResponseResult.fail();
        }
    }

    /**
     * 模糊查询
     *
     * @param dto dto
     * @return com.qf.commerce.resp.ResponseResult<com.github.pagehelper.PageInfo < com.qf.commerce.common.vo.DistributorOrderVo>>
     * @author 358
     * @since JDK 1.8
     */
    @GetMapping("/select")
    public ResponseResult<PageInfo<DistributorOrderVo>> select(@RequestBody DistributorOrderSelectDto dto) {
        try {
            return ResponseResult.success(distributorOrderService.select(dto));
        } catch (Exception e) {
            return ResponseResult.fail();
        }
    }

    /**
     * 添加经销订单
     *
     * @param dod dod
     * @return com.qf.commerce.resp.ResponseResult<java.lang.Integer>
     * @author 358
     * @since JDK 1.8
     */
    @PostMapping("/add")
    public ResponseResult<Integer> add(DistributorOrderDto dod) {
        try {
            return ResponseResult.success(distributorOrderService.addDistributorOrder(dod));
        } catch (Exception e) {
            return ResponseResult.fail();
        }
    }

    /**
     * 订单完成
     *
     * @param DistributorOrderId DistributorOrderId
     * @return com.qf.commerce.resp.ResponseResult<java.lang.Integer>
     * @author 358
     * @since JDK 1.8
     */
    @PutMapping("/status/success")
    public ResponseResult<Integer> statusSuccess(Integer DistributorOrderId) {
        try {
            return ResponseResult.success(distributorOrderService.statusSuccess(DistributorOrderId));
        } catch (Exception e) {
            return ResponseResult.fail();
        }
    }
}
